#============================================================
#	PlayerStateBlackboard
#============================================================
# @datetime: 2022-4-26 00:59:06
#============================================================
class_name PlayerStateBlackboard
extends BaseStateBlackboard


##  value 和状态节点的名称要保持一致
const States = {
	IDLE = "PlayerIdle", 
	MOVE = "PlayerMove", 
	JUMP = "PlayerJump", 
	ATTACK = "PlayerAttack", 
	SKILL = "PlayerSkill", 
	CLIMB_WALL = "PlayerClimbWall",		# 爬墙
	CLIMB_STAIRS = "PlayerClimbStairs", # 爬楼梯
}

var InputKey : _InputKey = _InputKey.new()
class _InputKey:
	var LEFT : String
	var RIGHT : String
	var UP : String
	var DOWN : String
	var ATTACK : String = "ui_accept"


var type_layer : PlayerTypeLayer
var controller : PlayerController


onready var attack_wrapper : AttackWrapper = WrapperHelper.get_attack(owner)
onready var equipment_wrapper : EquipmentWrapper = WrapperHelper.get_equipment(owner)
onready var property_wrapper : PropertyWrapper = WrapperHelper.get_property(owner)


#============================================================
#   内置
#============================================================
func _ready():
	# 等待 Player 中的 onready 节点都加载完成
	yield(owner, "ready")
	controller = get_layer().controller
	type_layer = get_host().type_layer
	
	InputKey.LEFT = get_layer().controller.input_controller.input_left
	InputKey.RIGHT = get_layer().controller.input_controller.input_right
	InputKey.UP = get_layer().controller.input_controller.input_up
	InputKey.DOWN = get_layer().controller.input_controller.input_down


#============================================================
#   Set/Get
#============================================================
#(override)
func get_host() -> Player:
	return owner as Player

func set_gravity_enabled(value: bool):
	get_move_controller().gravity_enabled = value

func get_layer() -> PlayerTypeLayer:
	return owner.type_layer as PlayerTypeLayer

func get_move_controller() -> SimplePlatformController:
	return controller.move_controller

func get_property(property):
	return property_wrapper.get_property(property)


#============================================================
#   角色状态
#============================================================
func is_moving() -> bool:
	return controller.move_controller.is_moving()

func is_falling():
	return (
		not get_host().is_on_floor()
		or controller.move_controller.get_last_velocity().y > 0
	)

func is_can_jump() -> bool:
	return controller.move_controller.jump_enabled

func is_can_move() -> bool:
	return controller.move_controller.move_enabled

func is_can_fall() -> bool:
	return (get_host() as KinematicBody2D).is_on_floor()

func is_can_attack() -> bool:
	return (attack_wrapper.is_enabled() 
		and equipment_wrapper.get_type_items(ItemBean.Type.WEAPON).size() > 0
	)

func is_can_climb_wall() -> bool:
	return get_host().is_on_wall()

func is_on_stairs() -> bool:
	return type_layer.collision.is_on_stairs()

func is_can_climb_staris() -> bool:
	return type_layer.collision.is_on_stairs()


